home *** CD-ROM | disk | FTP | other *** search
- Path: globe.indirect.com!snoopy
- From: chrism@xroads.com (Chris McCabe)
- Newsgroups: comp.lang.c++
- Subject: Re: Doesn't work, Why EXACTLY?
- Date: 18 Jan 1996 18:32:25 GMT
- Organization: Internet Direct, Inc.
- Message-ID: <4dlsg9$7a_004@news.indirect.com>
- References: <30FA8289.7AD6@bangate.compaq.com>
- NNTP-Posting-Host: snoopy.infograph.com
- X-Newsreader: News Xpress Version 1.0 Beta #3
-
- The compiler searches the scope hierarchy until it finds the
- function name it is looking for. It then looks for a best match
- within that scope ONLY. Base class methods will not be considered.
- In your case, it found func2 in class Y, then tried to match
- the X* to the Y* argument, which it can't do, so it gave the
- error. If you had no func2 method in class Y, it would have worked
- fine because the compiler would have searched the scope of class X
- instead.
- Whenever you overload a function name, you should consider
- overloading all instances of the function. Otherwise they
- will be "hidden" and unusable in the overloading scope.
- To fix your problem, simply add an inline function to class Y
- as follows:
- inline void func2(X* x) { X::func2(x); }
-
- This will fix the problem and does not incur any runtime overhead.
-
- Hope this helps,
- Chris
-
-
- In article <30FA8289.7AD6@bangate.compaq.com>,
- Saurabh Dixit <saurabhd@bangate.compaq.com> wrote:
- [stuff deleted...]
- >when I call func2 from a Derived object with a pointer
- >to an X object, i get - "... cannot convert from X to Y...".
- >So looks like compiler looks at method func2() in Derived
- >class. I would think the signature of the call would make
- >it look in Base class.
-